//
//  TYZLanguageTool.m
//  SC_APP
//
//  Created by 李贤立 on 2017/6/19.
//  Copyright © 2017年 Capfer. All rights reserved.
//

#import "TYZLanguageTool.h"

@implementation TYZLanguageTool
/**
 *  获取当前系统语言
 *
 *  @return 当前系统语言(如果不在设定的范围内,否则返回默认简体中文)
 */
+ (TYZLanguageType)currentLanguage {
    NSArray *languages = [NSLocale preferredLanguages];
    if (languages != nil) {
        NSString *currentLanguage = (NSString *)languages.firstObject;
        if ([currentLanguage hasPrefix:@"zh-Hant"]) {
            return LANGUAGE_TYPE_TRADITIONAL;
        }
    }
    return LANGUAGE_TYPE_SIMPLIFIED;
}
/**
 *  设置语言
 */
+ (void)configLanguageAndFonSize {
    // 优先读取偏好设置存储的语言和字体大小
    NSString *string = [[NSUserDefaults standardUserDefaults] stringForKey:Symbol_LanguageKey];
    if ([string isEqualToString:@"SIMPLIFIE"]) {
        CoreInfo.LanguageType = LANGUAGE_TYPE_SIMPLIFIED;
    } else if ([string isEqualToString:@"TRADITIONAL"]) {
        CoreInfo.LanguageType = LANGUAGE_TYPE_TRADITIONAL;
    } else {
        string = @"SIMPLIFIE";
        CoreInfo.LanguageType = [self currentLanguage];
    }
    NSLog(@"languageType: %@", string);
    CGFloat fontSize = [[NSUserDefaults standardUserDefaults] floatForKey:Symbol_FontSizeKey];
    if (fontSize < 5) fontSize = [UIFont systemFontSize];
    CoreInfo.fontSize = fontSize;
    // 存储字体大小
    [[NSUserDefaults standardUserDefaults] setFloat:CoreInfo.fontSize forKey:Symbol_FontSizeKey];
    NSLog(@"fontSize: %.f", CoreInfo.fontSize);
}
@end
